<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
      <#include "/common/elibs.html">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  </head><body>
    <div class="x-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <input type="hidden" id="idProclamation" name="idProclamation" value="${id}">
                <label for="title" class="layui-form-label">
                    <span class="x-red">*</span>公告名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="title" name="title" lay-verify="required" placeholder="请输入"
                           autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <!--<div class="layui-form-item">
                <label for="newsContent" class="layui-form-label">
                    <span class="x-red">*</span>公告描述
                </label>
                <div class="layui-input-inline">
                        <textarea id="newsContent"  name="newsContent" style="display: none;"
                                  class="layui-hide"></textarea>
                    <script>layui.use('layedit', function(){
                            var layedit = layui.layedit;
                            layedit.set({
                                uploadImage: {
                                    url: path + '/admin/news/imgUpload' //接口url
                                    ,type: 'post' //默认post
                                }
                            });
                            index = layedit.build('newsContent'); //建立编辑器});
                    </script>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>-->
            <div class="layui-form-item" id="parentsId" >
                <label for="proclamationType" class="layui-form-label">
                    <span class="x-red">*</span>公告类型
                </label>
                <div class="layui-input-inline">
                    <select lay-filter="tcaParentsId" id="proclamationType"
                            name="proclamationType" value="" lay-verify="required">
                        <option >请选择</option>
                        <option value="1">党务工作公告</option>
                        <option value="2">绩效考核公告</option>
                        <option value="3">业务工作公告</option>
                        <option value="4">安全工作公告</option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div><div class="layui-form-item">
                <label for="idxFiles" class="layui-form-label">
                    <span class="x-red">*</span>上传图片
                </label>
                <div class="layui-input-inline">
                    <img src="" id="imgUrl" name="imgUrl" width="600px"/><br><br><br>
                    <input type="hidden" id="idxFiles" name="idxFiles"  lay-verify="required">
                    <button type="button" class="layui-btn" id="upload" >
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button><script>
                        layui.use('upload', function(){
                            var upload = layui.upload;//执行实例
                            var uploadInst = upload.render({
                                elem: '#upload' //绑定元素
                                 ,url: path+'/pc/upload/uploadFile' //上传接口
                                ,accept: 'file' //允许上传的文件类型
                                ,done: function(res){
                                    //上传完毕回调
                                    $("#imgUrl").attr("src",res.data.filePath);
                                    $("#idxFiles").val(res.data.idSysFiles);
                                }
                                ,error: function(){
                                    //请求异常回调
                                }
                            });
                        });
                    </script>

                </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

            <div class="layui-form-item">
                <label for="idxFiles" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    提交
                </button>
            </div>
      </form>
    </div>
    <script>
        var params1 = {"idProclamation":$("#idProclamation").val(),"type":2};
        ajaxFun('get','/pc/proclamation/getProclamation',params1,function(data){
            if(data.code != 0){
                alertFun(data);
            }else{
                $("#title").val(data.data.title);
                $("#imgUrl").attr("src",data.data.filePath);
                $("#proclamationType").val(data.data.proclamationType);

            }
        })
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer,layedit = layui.layedit;//自定义验证规则
          form.verify({
              title: function(value){
                  if(value.length < 5){
                    return '名称不能为空';
                  }
                },
              proclamationType:function(value){
                  if(value.length < 5){
                      return '公告类型不能为空';
                  }
              },
              idxFiles: function(value){
                  if(value.length < 5){
                      return '图片不能为空';
                  }
              },
//            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            /*,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }*/
          });//监听提交
          form.on('submit(add)', function(t){
            var params = {
                idProclamation:$("#idProclamation").val(),
                title : $("#title").val(),
                idxFiles : $("#idxFiles").val(),
                proclamationType : $("#proclamationType").val(),
                type : 2
              }
            if(true){
                ajaxFun('post','/pc/proclamation/updateProclamation',params,function(data){
                    if(data.code != 0){
                        alertFun(data);
                    }else{
                        window.location.href= path + "/modules/notice/list.html";
                        console.log("success !");
                    }
                })
            }//发异步，把数据提交给php
            /*layer.alert("增加成功", {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });*/
            return false;
          });});
    </script></body></html>